package com.v2future.sjt.collegecheckingattendance.personal;

import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;

import com.v2future.sjt.collegecheckingattendance.MainActivity;
import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.utils.BaseResponseBean;
import com.v2future.sjt.collegecheckingattendance.utils.Constants;
import com.v2future.sjt.collegecheckingattendance.utils.PreferencesUtil;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.BaseRequestParams;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.NetTaskListener;
import com.v2future.sjt.collegecheckingattendance.utils.netutils.NetUtils;

import org.xutils.x;

import java.io.File;
import java.util.List;

import cn.jpush.android.api.JPushInterface;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;

/**
 * Created by Administrator on 2016/2/22.
 * 设置界面
 */
public class SettingActivity extends MainActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{

    LinearLayout changePwdLayout;

    CheckBox messageCb;

    /**
     * init first
     */
    @Override
    public void init() {

    }

    /**
     * init view
     */
    @Override
    public void initView() {
        setContentView(R.layout.activity_setting);
        initTitleBack(null);
        setTitleText(getString(R.string.setting));
        changePwdLayout = (LinearLayout) findViewById(R.id.layout_change_pwd);
        changePwdLayout.setOnClickListener(this);
        messageCb = (CheckBox) findViewById(R.id.cb_message);
        messageCb.setOnCheckedChangeListener(this);
    }

    /**
     * init after
     */
    @Override
    public void initAfter() {
        boolean pushAbled = PreferencesUtil.getSharedBooleanData(this, Constants.PREFERENCE_PUSH_ABLED);
        messageCb.setChecked(pushAbled);
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_change_pwd:
                Intent changePwdIntent = new Intent(SettingActivity.this, ChangePwdActivity.class);
                startActivity(changePwdIntent);
                break;
        }
    }

    /**
     * Called when the checked state of a compound button has changed.
     *
     * @param buttonView The compound button view whose state has changed.
     * @param isChecked  The new checked state of buttonView.
     */
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.cb_message:
                PreferencesUtil.setSharedBooleanData(SettingActivity.this, Constants.PREFERENCE_PUSH_ABLED, isChecked);
                if (isChecked) {
                    JPushInterface.resumePush(getApplication());
                }
                else {
                    JPushInterface.stopPush(getApplication());
                }
                break;
            default:
                break;
        }
    }
}
